package com.example.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.exam.entity.Notice;
import com.example.exam.service.NoticeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhang
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeServiceImpl noticeService;
    @PostMapping("/")
    public ResponseEntity<String> publish(@RequestBody Notice notice) {
        return noticeService.addNotice(notice) == 1 ? ResponseEntity.ok("发布成功") : ResponseEntity.badRequest().body("发布失败");
    }

    @GetMapping("/")
    public ResponseEntity<IPage<Notice>> notice() {
        return ResponseEntity.ok(noticeService.getNoticeById());
    }
}
